package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ISystemMsgService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.SystemMsgCreateValidate;
import com.mdd.admin.validate.SystemMsgUpdateValidate;
import com.mdd.admin.validate.SystemMsgSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.SystemMsgListedVo;
import com.mdd.admin.vo.SystemMsgDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/msg")
@Api(tags = "系统消息(快点/快商/平台通知公告)管理")
public class SystemMsgController {

    @Resource
    ISystemMsgService iSystemMsgService;

    @GetMapping("/list")
    @ApiOperation(value="系统消息(快点/快商/平台通知公告)列表")
    public AjaxResult<PageResult<SystemMsgListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated SystemMsgSearchValidate searchValidate) {
        PageResult<SystemMsgListedVo> list = iSystemMsgService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="系统消息(快点/快商/平台通知公告)详情")
    public AjaxResult<SystemMsgDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        SystemMsgDetailVo detail = iSystemMsgService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "系统消息(快点/快商/平台通知公告)新增")
    @PostMapping("/add")
    @ApiOperation(value="系统消息(快点/快商/平台通知公告)新增")
    public AjaxResult<Object> add(@Validated @RequestBody SystemMsgCreateValidate createValidate) {
        iSystemMsgService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "系统消息(快点/快商/平台通知公告)编辑")
    @PostMapping("/edit")
    @ApiOperation(value="系统消息(快点/快商/平台通知公告)编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody SystemMsgUpdateValidate updateValidate) {
        iSystemMsgService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "系统消息(快点/快商/平台通知公告)删除")
    @PostMapping("/del")
    @ApiOperation(value="系统消息(快点/快商/平台通知公告)删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iSystemMsgService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
